package com.fy.fyspace.common.auth.authenum;

import lombok.Getter;

/**
 * 空间用户角色枚举
 */
@Getter
public enum SpaceUserRoleEnum {

    SPACE_OWNER(2001L, "SPACE_OWNER", "空间所有者", 30L),
    SPACE_ADMIN(2002L, "SPACE_ADMIN", "空间管理员", 20L),
    SPACE_MEMBER(2003L, "SPACE_MEMBER", "空间成员", 10L),
    SPACE_VISITOR(2004L, "SPACE_VISITOR", "空间访客", 1L);

    /**
     * 角色id
     */
    private final Long roleId;

    /**
     * 角色编码
     */
    private final String roleCode;

    /**
     * 角色描述
     */
    private final String description;

    /**
     * 角色优先级(越大优先级越高)
     */
    private final Long priority;

    SpaceUserRoleEnum(Long roleId, String roleCode, String description, Long priority) {
        this.roleId = roleId;
        this.roleCode = roleCode;
        this.description = description;
        this.priority = priority;
    }

    // 通过roleCode获取枚举
    public static SpaceUserRoleEnum getEnumByRoleCode(String roleCode) {
        for (SpaceUserRoleEnum value : SpaceUserRoleEnum.values()) {
            if (value.getRoleCode().equals(roleCode)) {
                return value;
            }
        }
        return null;
    }

    // 通过roleId获取枚举
    public static SpaceUserRoleEnum getEnumByRoleId(Long roleId) {
        for (SpaceUserRoleEnum value : SpaceUserRoleEnum.values()) {
            if (value.getRoleId().equals(roleId)) {
                return value;
            }
        }
        return null;
    }
}